import dash
from dash import html, dcc
import feffery_antd_components as fac
import feffery_utils_components as fuc
from dash.dependencies import Input, Output, State

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        dcc.Location(id='url'),

        fuc.FefferyExecuteJs(id='execute-js'),

        # 背景粒子动画挂载点
        html.Div(
            id='particles-mount',
            style={
                'position': 'fixed',
                'top': 0,
                'left': 0,
                'right': 0,
                'bottom': 0,
                'zIndex': -1
            }
        ),

        # 登录控件
        # html.Div(
        #     [
        #         html.Div(
        #             html.Img(
        #                 src=dash.get_asset_url('imgs/logo.png'),
        #                 style={
        #                     'maxWidth': '300px',
        #                     'maxHeight': '100px',
        #                 }
        #             ),
        #             style={
        #                 'textAlign': 'center'
        #             }
        #         ),
        #
        #         html.Div(
        #             'xxx管理系统',
        #             style={
        #                 'fontSize': '26px',
        #                 'color': '#666',
        #                 'margin': '0 auto 40px auto',
        #                 'textAlign': 'center',
        #                 'fontWeight': '700',
        #             }
        #         ),
        #
        #         fac.AntdSpace(
        #             [
        #                 fac.AntdAlert(
        #                     closable=True,
        #                     message=fac.AntdText(
        #                         '测试账户：demo/demo123456',
        #                         style={
        #                             'color': '#67C23A'
        #                         }
        #                     ),
        #                     type='success'
        #                 ),
        #
        #                 fac.AntdInput(
        #                     placeholder='用户名',
        #                     size='large'
        #                 ),
        #
        #                 fac.AntdInput(
        #                     placeholder='密码',
        #                     size='large',
        #                     mode='password'
        #                 ),
        #
        #                 fac.AntdButton(
        #                     '登录',
        #                     type='primary',
        #                     size='large',
        #                     block=True
        #                 )
        #             ],
        #             direction='vertical',
        #             style={
        #                 'width': '100%'
        #             }
        #         )
        #     ],
        #     style={
        #         'paddingTop': '160px',
        #         'paddingBottom': '50px',
        #         'maxWidth': '350px',
        #         'marginLeft': 'auto',
        #         'marginRight': 'auto',
        #     }
        # )
    ]
)


@app.callback(
    Output('execute-js', 'jsString'),
    Input('url', 'pathname')
)
def render_js(pathname):

    return '''
// 第一个参数对应粒子效果挂载的容器id
particlesJS('particles-mount',
    {
        "particles": {
            "number": {
                "value": 80,
                "density": {
                    "enable": true,
                    "value_area": 800
                }
            },
            "color": {
                "value": "#c7d2dd"
            },
            "shape": {
                "type": "circle",
                "stroke": {
                    "width": 0,
                    "color": "#000000"
                },
                "polygon": {
                    "nb_sides": 5
                }
            },
            "opacity": {
                "value": 0.5,
                "random": false,
                "anim": {
                    "enable": false,
                    "speed": 1,
                    "opacity_min": 0.1,
                    "sync": false
                }
            },
            "size": {
                "value": 5,
                "random": true,
                "anim": {
                    "enable": false,
                    "speed": 40,
                    "size_min": 0.1,
                    "sync": false
                }
            },
            "line_linked": {
                "enable": true,
                "distance": 150,
                "color": "#c7d2dd",
                "opacity": 0.4,
                "width": 1
            },
            "move": {
                "enable": true,
                "speed": 2,
                "direction": "none",
                "random": false,
                "straight": false,
                "out_mode": "out",
                "attract": {
                    "enable": false,
                    "rotateX": 600,
                    "rotateY": 1200
                }
            }
        },
        "retina_detect": true,
        "config_demo": {
            "hide_card": false,
            "background_color": "#b61924",
            "background_image": "",
            "background_position": "50% 50%",
            "background_repeat": "no-repeat",
            "background_size": "cover"
        }
    }
);   
'''


if __name__ == '__main__':
    app.run_server()
